//
//  ContractDetail.m
//  Opper
//
//  Created by Le Dung on 4/16/13.
//  Copyright (c) 2013 LeDung. All rights reserved.
//

#import "ContractDetail.h"

@interface ContractDetail ()

@end

@implementation ContractDetail
@synthesize containView;
@synthesize contractArray;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}


-(void  )viewDidAppear:(BOOL)animated
{
    [StyleClass barButtonItemEdit:self left:YES right:YES];
}

-(void)rightPress
{
    ContractAddNew *page = [[[ContractAddNew alloc]init]autorelease];
    page.contractUnit =self.contractUnit;
    page.isAddContract =-1;
    page.member=self.member;
    [StyleClass currentScreen:self andDestination:page andHideBackButton:YES];
}

-(void)leftPress
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    [self createContain];
    [self loadData];
    [StyleClass createNavi:self andTitle:@"Abonnementem"];
    [StyleClass background:self.view];
    [self buttonTarget];
}

-(void)styleContaint
{
    [self.containView setBackgroundColor:[UIColor whiteColor]];
    self.containView.layer.shadowColor = [[UIColor blackColor] CGColor];
    self.containView.layer.shadowOffset = CGSizeMake(0.0, 2.0);
    self.containView.layer.shadowOpacity = 1.0f;
}
-(void)buttonTarget
{
    UIButton *opperButton =[UIButton buttonWithType:UIButtonTypeCustom];
    opperButton.frame =CGRectMake(10, 250, 300, 40);
    [opperButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [opperButton setBackgroundImage:[StyleClass nGreen] forState:UIControlStateNormal];
    opperButton.titleLabel.textColor=[UIColor whiteColor];
    [opperButton setTitle:@"Opper" forState:UIControlStateNormal];
    [opperButton addTarget:self action:@selector(gotoDocument) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:opperButton];
    
}

-(void)gotoDocument
{
    Document *page = [[[Document alloc]init]autorelease];
    page.contractInfo= self.contractUnit;
    page.isInstane=1 ;
    page.member=self.member;
    [StyleClass currentScreen:self andDestination:page andHideBackButton:YES];
}

-(void)loadData
{
    NSArray *titleLabel =[NSArray arrayWithObjects:self.contractUnit.contractName,self.contractUnit.contractId,self.contractUnit.contractNumber,self.contractUnit.contractStartDate ,self.contractUnit.contractEndDate ,nil];
    for(int i = 0 ; i<=4 ; i++)
    {
        if(i != 1)
        {
        UILabel *label =[[UILabel alloc]initWithFrame:CGRectMake(160, 12+30*i, 170, 30)];
        label.font=[UIFont systemFontOfSize:14];
        label.backgroundColor =[UIColor clearColor];
        [self.containView addSubview:label];
        label.text =[titleLabel objectAtIndex:i];
        [label release];
        }
        else
        {
            UIImageView *logo =[[UIImageView alloc]initWithFrame:CGRectMake(160, 41, 40, 29)];
            [self.containView addSubview:logo];
            logo.backgroundColor =[UIColor greenColor];
            [logo    release];
        }
    }
    
}


-(void)createContain
{
    self.containView =[[UIView alloc]initWithFrame:CGRectMake(10, 30, 300, 210)];
    [self.view addSubview:self.containView];
    [self styleContaint];

    NSArray *titleLabel =[NSArray arrayWithObjects:@"Product",@"Maatschapij",@"Polis/Contractnummer",@"Ingangsdatum" ,@"Verval datum" ,nil];
    for(int i = 0 ; i<=4 ; i++)
    {
        UIImageView *line =[[UIImageView alloc]initWithFrame:CGRectMake(0, 40+i*30, 300, 1)];
        [self.containView addSubview:line];
        [line setBackgroundColor:[UIColor brownColor]];
        [line release];
        
        
        
        //array title
        
        
        UILabel *label =[[UILabel alloc]initWithFrame:CGRectMake(5, 12+30*i, 170, 30)];
        label.font=[UIFont systemFontOfSize:14];
        label.backgroundColor =[UIColor clearColor];
        [self.containView addSubview:label];
        label.text =[titleLabel objectAtIndex:i];;
        [label release];
    }
    
    UILabel *label =[[UILabel alloc]initWithFrame:CGRectMake(5, 168, 150, 30)];
    label.text=@"Opzegalarm instellen";
    label.backgroundColor =[UIColor clearColor];
    label.font=[UIFont systemFontOfSize:14];
    [self.containView addSubview:label];
    [label release];
    
    UISwitch *terminalSwitch =[[UISwitch alloc]initWithFrame:CGRectMake(160, 170, 70, 30)];
    [self.containView addSubview:terminalSwitch];
    [terminalSwitch setOn:NO];
    if([self.contractUnit.terminalAlert isEqualToString:@"1"])
    {
        [terminalSwitch setOn:YES];
    }
    [terminalSwitch setUserInteractionEnabled:NO];
    [terminalSwitch release];
}



- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
